CROSS_COMPILE ?= 
TARGET ?= main

CPP             := $(CROSS_COMPILE)g++
LD              := $(CROSS_COMPILE)ld
OBJCOPYld       := $(CROSS_COMPILE)objcopy
OBJDUMPld       := $(CROSS_COMPILE)objdump

INCLUDES        := ./ \
					src/solution
SRCDIRS         := ./ \
					src/solution
INCLUDE         := $(patsubst %, -I %, $(INCLUDES))
SFILES          := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*S))
CFILES          := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*cpp))
SFILENDIR       := $(notdir $(SFILES))
CFILENDIR       := $(notdir $(CFILES))
SOBJS           := $(patsubst %, obj/%, $(SFILENDIR:.S=.o))
COBJS           := $(patsubst %, obj/%, $(CFILENDIR:.cpp=.o))
OBJS            := $(SOBJS) $(COBJS)
VPATH           := $(SRCDIRS)

$(TARGET):$(OBJS)
	$(CPP) -o $@ $^

# 依赖文件为 obj/start.o形式的文件转换成start.S
$(SOBJS) : obj/%.o : %.S
	$(CPP) -c $(INCLUDE) -o $@ $<

# 依赖文件为 obj/key.o形式的文件转换成key.c
$(COBJS) : obj/%.o : %.cpp
	$(CPP) -c $(INCLUDE) -o $@ $<

# 声明伪目标
.PHONY:clean
# 命令前面加 -表示命令执行出错忽略继续执行 
clean:
	-rm -rf *.o $(TARGET).bin $(TARGET).elf $(TARGET).dis $(COBJS) $(SOBJS)